package com.easylinkin.linkappapi.alarm.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.alarm.entity.AlarmNotice;
import com.easylinkin.linkappapi.alarm.service.AlarmNoticeService;
import com.easylinkin.linkappapi.common.model.RequestModel;
import javax.annotation.Resource;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * <p>
 * 告警通知日志 前端控制器
 * </p>
 *
 * @author TongJie
 * @since 2020-05-14
 */
@Api(value="告警通知日志",tags={"告警通知日志"})
@RestController
@RequestMapping("/alarm/alarmNotice")
public class AlarmNoticeController {

    @Resource
    private AlarmNoticeService service;

    /**
     * 获取告警通知分页数据（管理员获取全部,普通用户只看自己）
     * @param requestModel
     * @return
     */
    @ApiOperation("获取告警通知分页数据")
    @PostMapping("getPage")
    public RestMessage getAlarmPage(@RequestBody RequestModel<AlarmNotice> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<AlarmNotice> record = service.getAlarmNoticePage(requestModel.getPage(), requestModel.getCustomQueryParams());
        return RestBuilders.successBuilder().data(record).build();
    }

    /**
     * 获取告警通知数据list（管理员获取全部,普通用户只看自己）
     * @param alarmNotice
     * @return
     */
    @ApiOperation("获取告警通知数据list")
    @PostMapping("get")
    public RestMessage getAlarmNotices(@RequestBody AlarmNotice alarmNotice) {
        Assert.notNull(alarmNotice, "参数不能为空");
        return RestBuilders.successBuilder().data(service.getAlarmNotices(alarmNotice)).build();
    }

    /**
     * 根据权限获取告警通知联系人
     * @param requestModel
     * @return
     */
    @ApiOperation("根据权限获取告警通知联系人")
    @PostMapping("getNoticeUser")
    public RestMessage getNoticeUser(@RequestBody AlarmNotice requestModel) {
        Assert.notNull(requestModel, "参数不能为空");
        return RestBuilders.successBuilder().data(service.getNoticeUser(requestModel)).build();
    }

}
